package DAO;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import DBUntil.DbHelper;
import each_class.SongClass;

public class Singers_DAO {
	private static DbHelper db = new DbHelper();

	//
	public static  boolean judgeExist(String id) throws IOException {
		String sql = "select singer_id from singers where singer_id=?";
		Map<String, Object> map = db.findsingle(sql, id);
		if (null == map) {
			return true;
		}
		return false;
	}

	//
	public static  boolean isdelet(String id) throws IOException {
		String sql = "select singer_id from singers where singer_id like %id%";
		List<Map<String, Object>> map = db.findMutip(sql, id);
		if (map.size() < 1) {
			return true;
		}
		return false;
	}

	// 添加
	public static  int addSingers(String singer_id, String singer_name) throws Exception {
		if (judgeExist(singer_id)) {
			String sql = "insert into singers values(?,?)";
			return db.update(sql, singer_id, singer_name);
		} else {
			return 0;
		}
	}

	public static  Map<String, Object> find(String singer_id) throws IOException {
		String sql = "select singer_id,singer_name from singers where singer_id=?";
		return db.findsingle(sql, singer_id);
	}

	// 删除
	public static  int disSingers(String singer_id) throws Exception {
		if (isdelet(singer_id)) {
			String sql = "delete from singers where singer_id=?";
			return db.update(sql, singer_id);
		}

		return 0;
	}
}
